  
var orderManage = function() {

	var _init = function() {

		var table = $('#table_order');

		var tableUnit=table.dataTable({
			"processing": true,
			// 开启服务器模式
			serverSide: true,
			"ajax": {
				url:"/a/wxconf/comm/dtl",
				data:{"type":'1'}  //提现
			},
			"autoWidth": true,
			"order":false,
			"columns": [
				{
					"data": "createDate",//申请日期
					"render":function(data, type, row, meta) {
						return moment(data).format('YYYY-MM-DD HH:mm');
					}
				},
				{
					"data": "null",//申请人
					"render": function(data, type, row, meta) {
						if(row.user.nickName){
							return row.user.nickName;
						}else{
							return "未绑定微信昵称";
						}
				      }
				},
				{
					"data": "phone",//手机
					"render": function(data, type, row, meta) {
						if(row.user.mobile){
							return row.user.mobile;
						}else{
							return "未绑定手机";
						}
				      }
					
				},
				{
					"data": "amount",//提现金额
					"render": function(data, type, row, meta) {
						if(data){
							return data/100
						}else{
							return "--"
						}
					   
				      }
				},
				{
					"data":"accountName"//提现账户
				
				},/*{
					"data":"account"//提现账号
				
				},*/{
					"width": "20%",
					"data":"tradeNo",//交易单号
						"render":function(data, type, row, meta) {
							if(data){
								return data;
							}else{
								return "--";
							}
							
						}
				
				},{
					"data":"tradeDate",//交易时间
					"render":function(data, type, row, meta) {
						if(data){
							return moment(data).format('YYYY-MM-DD HH:mm');
						}else{
							return "--";
						}
						
					}
				},
			
				{
					"data" : "status",
					"orderable": false,
					"render":function(data, type, row, meta) {
						if(data=='2'){
							return "已结算";
						}else{
							  return  "<button type=\"button\" class=\"btn btn_settlement\">结算登记</button>"

						}
					}
				},
			
				],
				"language": {
					url: '/assets/pages/Chinese.json'
				},
				"pageLength": 10,
				
				"order": [
					[0, "desc"]
					],
					"columnDefs": [{
						"orderable": false,
						"targets": [1,2,7]
					}],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
            "<t>" +
            "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {},
           
		});

						
	}

	return {
		init: function() {
			_init();
		}

	};

}();


//用户动态查询
$('#doQuery').click(function(event){
	var name =   $("#search input[name='name']").val();
	var phone =   $("#search input[name='phone']").val();
	var status =   $("#search select[name='status']").val();
	var param={"accountName":name,"account":phone,"status":status,"type":'1'};
	$('#table_order').DataTable().search(JSON.stringify(param)).draw();
});


$('#table_order').on('click', '.btn_settlement', function(event) {
	var oData_arr = $('#table_order').DataTable().rows($(this).parents("tr")).data(); // 操作行对象
	$('#modal_new_role').find(' [name="id"]').val(oData_arr[0].id);
	var date=oData_arr[0].createDate;
	date=mdTool.fmtDate(date);
	$('#modal_new_role [name="applyTime"]').html(date);  
	$('#modal_new_role [name="amount"]').html(oData_arr[0].amount/100);
	$('#modal_new_role [name="name"]').html(oData_arr[0].user.nickName  );
	$('#modal_new_role [name="accountName"]').html(oData_arr[0].accountName);
	
    $(' .help-block').html(''); 

    $('#modal_new_role').modal('show');
});


$('#btn_submit').click(function(event){
    var param = $("#form_role_new").serializeObject();
	$.ajax({
		url : '/a/wxconf/comm/withdrawals',
		type : 'POST',
		dataType : 'json',
		contentType:"application/json; charset=utf-8",
		data : JSON.stringify(param),
	}).done(function(data) {
		if (data.status === '1') {
			// 正确
		    $('#modal_new_role').modal('hide');
		    $("#table_order").DataTable().ajax.reload(); // 刷新table

		} else if (data.status === '2') {
//			错误
			mdTool.showMessageForHelpBlock(data.message);
		}
	});
});




$(function() {

	orderManage.init();


});